/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.doeacc.tms.domain;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;

/**
 *
 * @author slok
 */
@Entity(name = "Roles")
public class Role implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Column(length = 20, nullable = false)
    private String roleId;
    @Column(length = 50)
    private String roleName;
    @OneToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "UserRoles", joinColumns = {
        @JoinColumn(name = "roleId")}, inverseJoinColumns = {
        @JoinColumn(name = "loginId")})
    private Set<User> users;

    public Set<User> getUsers() {
        return users;
    }

    public void setUsers(Set<User> users) {
        this.users = users;
    }

    public String getRoleId() {
        return roleId;
    }

    public void setRoleId(String roleId) {
        this.roleId = roleId;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    @Override
    public int hashCode() {
        int hash = 8;
        hash = 97 * hash + (this.roleId != null ? this.roleId.hashCode() : 0);
        hash = 97 * hash + (this.roleId != null ? this.roleId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Role)) {
            return false;
        }
        Role other = (Role) object;
        if ((this.roleId == null && other.roleId != null) || (this.roleId != null && !this.roleId.equals(other.roleId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return roleName;
    }
}
